/**
 * @see https://umijs.org/docs/max/access#access
 * */
export default function access(initialState: { currentUser?: API.CurrentUser } | undefined) {
  const { currentUser } = initialState ?? {};
  var hasRoute=JSON.parse(currentUser?.hasRoute==undefined?'[]':currentUser?.hasRoute);
  var hasOperate=JSON.parse(currentUser?.hasOperate==undefined?'[]':currentUser?.hasOperate);

  return {
    // 在此定义返回角色，通过currentUser所含的权限值 进行计算
    // 用函数方式
    canAdmin: currentUser && currentUser.access === 'admin',
    routeFilter:(route:any)=>hasRoute.includes(route.name),
    operateFilter:(operateName:any)=>hasOperate.includes(operateName),
  };
}
